package plenprojects.chatservice;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import plenprojects.security.SecurityToken;

public class TokenContainer {
	
	private final Map<String, SecurityToken> tokenByUsername = new ConcurrentHashMap<String, SecurityToken>();
	private final Map<String, SecurityToken> tokenByValue = new ConcurrentHashMap<String, SecurityToken>();
	
	public void submitToken(SecurityToken token) {
		
		tokenByUsername.put(token.getUsername(), token);
		tokenByValue.put(token.toString(), token);
	}
	
	public void invalidateToken(SecurityToken token) {
		
		tokenByUsername.remove(token.getUsername());
		tokenByValue.remove(token.toString());
	}
	
	public SecurityToken getTokenByUsername(String username) {
		
		return tokenByUsername.get(username);
	}
	
	public SecurityToken getTokenByValue(String value) {
		
		return tokenByValue.get(value);
	}
}
